<%--
*
* 获取xml数据
*
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.sky.fisher.model.GridModel"%>
<%@ page import="com.sky.fisher.service.FisherService"%>
<%@ page import="com.sky.common.http.HTTPUtils"%>
<%@ page import="org.apache.commons.logging.Log"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:directive.page import="com.sky.fisher.exporter.XMLExporter"/>
<jsp:directive.page import="com.sky.fisher.service.SupcanService"/>
<jsp:directive.page import="com.sky.common.string.StringUtils"/>
<jsp:directive.page import="com.sky.fisher.cache.AbstractCacher"/>
<%
	Log logger = LogFactory.getLog(FisherService.class);
	Map<String, String[]> paramters = null;
	String strSQL = "";
	String xmlresult="";
	try{
		paramters = request.getParameterMap(); 
		logger.debug("Grid：\n"+paramters.get(FisherService.PARAMETER_GRID)[0]);
		logger.debug("参数：\n"+HTTPUtils.getParameterMap(request));
		GridModel grid = FisherService.getGrid(paramters.get(FisherService.PARAMETER_GRID)[0]); 
		grid.setRequest(request);
		String recalculate=paramters.get(SupcanService.PARAMETER_RECALCULATE)!=null?paramters.get(SupcanService.PARAMETER_RECALCULATE)[0]:null;
		String cache=paramters.get(SupcanService.PARAMETER_CACHE)!=null?paramters.get(SupcanService.PARAMETER_CACHE)[0]:null;
		if("true".equalsIgnoreCase(recalculate)){//重新计算
			strSQL = FisherService.getSQL(grid,paramters); 
			xmlresult=new XMLExporter().getXML(grid,paramters,strSQL);	
			if(!StringUtils.isEmpty(cache)){//缓存
				AbstractCacher cacher =SupcanService.getCacher(cache);
				cacher.cache(paramters,grid,xmlresult);	
			}		
		}else if(!StringUtils.isEmpty(cache)){//缓存
			AbstractCacher cacher =SupcanService.getCacher(cache);
			if(cacher.isCache(paramters,grid)){
				xmlresult=cacher.load(paramters,grid);
			}else{
				strSQL = FisherService.getSQL(grid,paramters); 
				xmlresult=new XMLExporter().getXML(grid,paramters,strSQL);
				cacher.cache(paramters,grid,xmlresult);				
			}
		}else{
			strSQL = FisherService.getSQL(grid,paramters); 
			xmlresult=new XMLExporter().getXML(grid,paramters,strSQL);			
		}
		response.setContentType("text/html"); 
		out.println(xmlresult); 
	}catch(Throwable e){		
	  	e.printStackTrace();
	  	logger.error("Grid：\n"+paramters.get(FisherService.PARAMETER_GRID)[0]);
	  	logger.error("参数：\n"+paramters);
	  	logger.error("SQL：\n"+strSQL);	  	
	  	logger.error(e.getMessage(),e);
		throw e;
	}
%>
